Data Sources
import geopandas as gpd
# Data source - https://www.hydrosheds.org/products/hydrorivers
samerica_rivers = gpd.read_file("../resources/data/a00000009.gdbtable")
samerica_rivers = samerica_rivers.loc[samerica_rivers['ORD_FLOW'] < 7]
print(samerica_rivers.columns)
Index(['HYRIV_ID', 'NEXT_DOWN', 'MAIN_RIV', 'LENGTH_KM', 'DIST_DN_KM',
'DIST_UP_KM', 'CATCH_SKM', 'UPLAND_SKM', 'ENDORHEIC', 'DIS_AV_CMS',
'ORD_STRA', 'ORD_CLAS', 'ORD_FLOW', 'HYBAS_L12', 'Shape_Length',
'geometry'],
dtype='object')
# Data source - https://github.com/nvkelso/natural-earth-vector/blob/master/10m_cultural/ne_10m_admin_0_countries.shp
country_shapefiles = gpd.read_file("../resources/data/ne_10m_admin_0_countries.shp")
samerica = country_shapefiles.loc[country_shapefiles['ADMIN'] == 'Brazil']
samerica_rivers = gpd.sjoin(samerica_rivers, samerica, predicate='within')
samerica_rivers = samerica_rivers[['DIST_UP_KM', 'geometry']]
samerica_rivers.to_file("../resources/data/rivers.geojson", driver="GeoJSON")
# Data source - https://www.hydrosheds.org/products/hydrorivers
samerica_rivers = gpd.read_parquet("../resources/data/rivers.parquet.gzip")
samerica_rivers.plot(color='blue', lw=0.1)
<AxesSubplot:>
import numpy as np
leftSpan = np.amax(samerica_rivers['DIST_UP_KM']) - np.amin(samerica_rivers['DIST_UP_KM'])
rightSpan = 1 - 0.1
valueScaled = (samerica_rivers['DIST_UP_KM'] - np.amin(samerica_rivers['DIST_UP_KM'])) / leftSpan
samerica_rivers['LW_DIST_UP_KM'] = 0.1 + (valueScaled * rightSpan)
samerica_rivers.plot(edgecolor='face', color='blue', lw=samerica_rivers['LW_DIST_UP_KM'])
<AxesSubplot:>
# Data source - https://www.hydrosheds.org/products/hydrobasins
basins = gpd.read_file("../resources/data/hydrobasins_southam.shp")
print(basins.columns)
Index(['SUB_BAS', 'TO_BAS', 'MAJ_BAS', 'MAJ_NAME', 'SUB_NAME', 'SUB_AREA',
'MAJ_AREA', 'LEGEND', 'geometry'],
dtype='object')
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = plt.subplot(1, 3, 1)
basins.plot(ax=ax1, column='SUB_NAME', edgecolor='face')
ax1.axis('off')
ax2 = plt.subplot(1, 3, 2)
basins.plot(ax=ax2, column='MAJ_NAME', edgecolor='face')
ax2.axis('off')
plt.show()
import pandas as pd
colours_i_like = ['black', 'blue', '#808000', '#483d8b', '#dc143c',
'#000080', 'green', '#8b008b', '#ff4500', '#ffa500', '#008856',
'#882D17', '#228B22', '#3cb371', '#875692', '#2f4f4f', '#0000ff',
'#ff00ff', '#1e90ff', '#db7093', '#ff1493', 'darkgreen',
'#ee82ee', '#A1CAF1', 'orange']
colors_df = pd.DataFrame({'basin': basins.MAJ_NAME.unique().tolist(), 'colors': colours_i_like})
basins = pd.merge(basins, colors_df, left_on='MAJ_NAME', right_on='basin', how='left')
basins.plot(column='MAJ_NAME', edgecolor='face', color=basins['colors'])
<AxesSubplot:>
fig, ax = plt.subplots()
basins.plot(ax=ax, column='MAJ_NAME', edgecolor='face', color=basins['colors'])
basins.boundary.plot(ax=ax, color='black', lw=0.1)
plt.show()